//
//  BaseViewController.m
//  JRWD
//
//  Created by hejin on 16/2/15.
//  Copyright © 2016年 hejin. All rights reserved.
//

#import "BaseViewController.h"
#import "AppMacro.h"

@interface BaseViewController ()
{
    MBProgressHUD *dHUD;
}

@end

@implementation BaseViewController

#pragma mark - Life Cycle Methods

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addGestureRecognizer:[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipToLastLevelPage)]];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


- (void)swipToLastLevelPage {

    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - 暂无内容
- (UIImageView *)addNoDataView:(CGRect )frame {

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nonenone"]];
    imageView.frame = frame;
    [self.view addSubview:imageView];
    return imageView;
}


#pragma mark - 导航栏左右标签
- (void)addBackButton {
    // left nav item

    UIImage *buttonImage = [UIImage imageNamed:@"arrow_back"];
    
    UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [aButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
    
    aButton.frame = CGRectMake(0.0, 0.0, buttonImage.size.width,   buttonImage.size.height);
    
    UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];
    
    [aButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.navigationItem setLeftBarButtonItem:aBarButtonItem];
    
}

- (IBAction)backAction:(id)sender {

    [self.navigationController popViewControllerAnimated:YES];
}

- (void)addCloseButton {
    // right nav item
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_close"] style:UIBarButtonItemStylePlain target:self action:@selector(closeAction:)];
    self.navigationItem.leftBarButtonItem = leftItem;
}

- (IBAction)closeAction:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}



#pragma mark - 网络加载进度
/**
 *  ProgressHUD
 */
- (void)showProgressHUD
{
    if (!dHUD) {
        
        dHUD = [[MBProgressHUD alloc] initWithView:[UIApplication sharedApplication].keyWindow.rootViewController.view];
        [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:dHUD];
        
        //如果设置此属性则当前的view置于后台
        dHUD.dimBackground = NO;
        
        //设置对话框文字
        dHUD.labelText=@"努力加载中...";
        
    }
    [dHUD show:YES];
}
//隐藏
- (void)dismissProgressHUD
{
    if (dHUD){
        [dHUD removeFromSuperview];
        dHUD = nil;
    }
}

@end
